<?php
if (count($this->taskView->tasks) > 0)
    foreach ($this->taskView->tasks as $task):
        $signal = $task->signal;
        $messageTags = $signal->findTag();
        $timestamp = $signal->date->format("U");
        $status = $task->status;
        $completeText = "";
        $completeAction = "Mark Complete";
        $user1 = User::withId($task->taskUserId);
        $user2 = User::withId($task->taskAssignedTo);
        $message = $signal->message;
        $dateCreated = $task->taskDateCreated;
        $stream = Stream::withId(base64_encode($signal->streamID));

        $date = new DateTime($message->getTime());
        $timestamp = $date->format("U");
        $twitter = Twitter::getTwitters();
        $facebook = Facebook::getFacebooks();
        $google = Google::getGoogles();
        $linkedin = LinkedIn::getLinkedIns();
        if ($status == 2) {
            $completeText = "completed";
            $completeAction = "Undo Complete";
        }
        $videoId = '';
        if ($message->getSource() == 'www.youtube.com') { //Parse youtube links
            $url = $message->getURL();
            $urlParams = explode('?v=', $url);
            $videoIdTemp = $urlParams[1];
            $idParams = explode('&', $videoIdTemp);
            $videoId = $idParams[0];
            $embedUrl = "https://youtube.googleapis.com/v/" . $videoId;
        }
        ?>
        <li id="<?php echo $task->taskId; ?>" messageid="<?php echo $signal->message->getId() ?>" threadid="<?php echo $signal->message->getThreadId() ?>" streamid="<?php echo $signal->streamId ?>">
            <div class="mozaic-widget item-285541 widget-mention_signal" data-guid="widget-183" data-id="285541" data-initialized="true" >
                <div class="mention-container alert-container signals-mention main-mention signal-orange" id="mention-">
                    <div class="mention-left-content">
                        <div class="annotable-extra-container">
                            <div class="mozaic-widget widget-signal_annotable_extra" data-guid="widget-190" data-initialized="true" >
                                <p class="mention-time-stamp extend signals-time-stamp-2" data-timestamp="<?php echo $timestamp; ?>" data-timestamp-format="timeago"><?php echo Utils::humanTiming($date->format("U")); ?></p>

                                <p class="mention-type"><a class="platform-link action-color-active" data-value="" rel="tooltip" title="Show all mentions">mention</a></p>

                                <p class="mention-type additional-timestamp" data-timestamp="<?php echo $timestamp; ?>" data-timestamp-format="MMM D YYYY h:mm A"><?php echo $message->getTime() ?></p>
                            </div>
                        </div>

                        <div class="mention-circle-holder <?php echo StreamController::getSMTIcon($message->getType()); ?>">
                            <i class="icon-cirlce-background"></i>
                            <div class="icon-circle-mention background-twitter ">
                                <i class="icon-mention-<?php echo StreamController::getSMTIcon($message->getType()); ?> responsive-l1"></i>
                            </div>
                        </div>
                    </div>

                    <div class="mention-right-content">
                        <div class="mention-right-wrapper">
                            <div class="mention-right-container extend">
                                <div class="mention-content">
                                    <div class="mention-core">
                                        <div class="mention-core-wrapper">
                                            <div class="mention-content-full"  style="margin-left: 0">
                                                <p class="mention-type additional-timestamp signals-additional-time" data-timestamp="<?php echo $timestamp; ?>" data-timestamp-format="MMM D YYYY h:mm A"><?php echo $date->format("M d Y h:m A") ?></p>
                                                <div class="context-border-container" style="float: right; margin-top: 16px;">
                                                    <a href="<?php echo $message->getURL(); ?>" target="_blank">

                                                    </a>
                                                </div>
                                                <div class="timeline-content-tweak">
                                                    <p class="author-name"><a class="action-color-hover" href="<?php echo $message->getURL(); ?>" target="_blank"><?php echo $message->getThreadTitle(); ?></a></p><span class="mention-display-name"><?php echo $message->author ?></span>
                                                </div>
                                                <a class="btn-source" href="<?php echo $message->getURL(); ?>" target="_blank">
                                                    <i class="icon-action-viewsource action-color-normal"></i>
                                                </a>
                                                <div class="resource-text-container" >

                                                    <p class="mention-short-url"><img style="width:16px;margin-right:5px;" src="http://www.google.com/s2/favicons?domain=<?php echo $message->getURL(); ?>" /><a class="action-color-active" href="<?php echo $message->getURL(); ?>" target="_blank"><?php
                                                            $parse = parse_url($message->getURL());
                                                            echo str_ireplace('www.', '', $parse["host"]);
                                                            ?></a><a style="margin-left: 5px; padding-left: 5px; border-left: 1px solid orange;" class="action-color-active" href="<?php echo $message->getURL(); ?>" target="_blank"><?php
                                                            echo $message->getAuthor();
                                                            ?></a><a class="toggle-link" style="margin-left: 5px; padding-left: 5px; border-left: 1px solid orange;" class="action-color-active">show links</a></p>
                                                </div>
                                                <div class="mention-text original-mention"><?php
                                                    $text = trim(rtrim($signal->text, 'null'));
                                                    $text = str_replace('(javascript:void(0))', '', $text);
                                                    $text = str_replace("\n", "<br>", $text);
                                                    eregi("<blockquote>(.*)</blockquote>", $text, $data);
                                                    $blockQuote = $data[0];
                                                    $text = str_replace($blockQuote, "{blockquote}", $text);
                                                    if (substr_count($text, " ") > 100) {
                                                        //find the 100th char(' ')
                                                        $endpos = 200;
                                                        $endpos = strpos($text, " ", $endpos);
                                                        echo Signal::parseLinks(str_replace("{blockquote}", $blockQuote, substr($text, 0, $endpos)));
                                                        ?>
                                                        <span class="readmore-threedot">...</span>
                                                        <span class="readmore spanshow" onclick="expand(this);" style="color: orange; cursor: pointer; white-space: nowrap;">Read more</span>
                                                        <span class="readmore-content hide"><?php echo Signal::parseLinks(str_replace("{blockquote}", $blockQuote, substr($text, $endpos))); ?></span>
                                                        <span class="readmore spanshow hide" onclick="unexpand(this);" style="color: orange; cursor: pointer; white-space: nowrap;">Show less</span><?php
                                                    } else
                                                        echo Signal::parseLinks(str_replace("{blockquote}", $blockQuote, $text));
                                                    ?>
                                                    <?php if ($videoId) : ?>
                                                        <div class="video-thumb-container" id="imagecontainer-<?php echo $videoId; ?>">
                                                            <div class="thumbnail-overlay play-video" data-video-id="<?php echo $videoId; ?>">
                                                                <i class="icon-play play-video"></i>
                                                            </div>
                                                            <img class="video-thumnail" src="http://img.youtube.com/vi/<?php echo $videoId; ?>/0.jpg">
                                                        </div>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="tags-holder-container first-two-tags">
                                    <div class="mozaic-widget mozaic-initialized widget-annotable_tags" <?php if (count($messageTags) > 2) echo 'style="margin-right: 20px;"'; ?>>
                                        <?php
                                        $index = 0;
                                        foreach ($messageTags as $tag) {
                                            echo '<div class="tag-holder-container"><label>' . $tag->tagName . '</label><a tagid="' . $tag->tagId . '" class="remove-tag">x</a></div>';
                                            if ($index >= 2)
                                                $tagsTooltip[] = $tag->tagName;
                                            $index++;
                                        }
                                        ?>
                                    </div>
                                </div>
                                <div class="more-tags-holder" <?php if (count($messageTags) > 2) echo 'style="display: block"'; ?>>
                                    <span>...</span>
                                    <div class="more-tags-tooltip">
                                        <div class="arrow-icon"></div>
                                        <div class="tags-holder-container more-tags-container">
                                            <div class="mozaic-widget mozaic-initialized widget-annotable_tags"><?php
                                                echo implode('<br>', $tagsTooltip);
                                                ?></div>
                                        </div>
                                    </div>
                                </div>

                                    <div class="signal-action-bar-container">
                                        <div class="mozaic-widget widget-signal_action_bar" data-guid="widget-194" data-initialized="true" >


                                            <div class="signal-review-bar">
                                                <p>Retweet or Reply</p>
                                            </div>

                                            <ul class="mention-action-bar">
                                                <?php if ($twitter['accountid'] != 'undefined' || $facebook['accountid'] != 'undefined' || $google['accountid'] != 'undefined' || $linkedin['accountid'] != 'undefined'): ?>
                                                    <li class="mention-action-button retweet_dropdown" messageId="<?php echo $signal->messageID; ?>" streamId="<?php echo $signal->streamID; ?>">
                                                        <div class="btn-group dropdown">
                                                            <button href="#" class="btn btn-danger retweet action-color-background dropdown-toggle" data-toggle="dropdown" data-platform-id="377747108537061378">
                                                                <i class="icon-action-retweet"></i><div>Share</div><i class="icon-action-dropdown"></i>
                                                            </button>
                                                            <div class="tag-mention">
                                                                <span class="square-hack"></span>
                                                                <div class="dropdown-menu">
                                                                    <ul class="overview">
                                                                        <?php if ($twitter['accountid'] != 'undefined') : ?>
                                                                            <li data-id="902">
                                                                                <a class="retweet_this" data-action="retweet" data-platform-id="377747108537061378"><i class="icon-circle-list"></i>Twitter</a>
                                                                            </li>
                                                                        <?php endif; ?>
                                                                        <?php if ($facebook['accountid'] != 'undefined') : ?>
                                                                            <li data-id="903">
                                                                                <a class="retweet_this" data-action="facebook" data-platform-id="377747108537061378"><i class="icon-circle-list"></i>Facebook</a>
                                                                            </li>
                                                                        <?php endif; ?>
                                                                        <?php if ($google['accountid'] != 'undefined') : ?>
                                                                            <li data-id="902">
                                                                                <a id="myBtn" class="retweet_this demo g-interactivepost" 
                                                                                   data-clientid="208044150507.apps.googleusercontent.com"
                                                                                   data-contenturl="<?php echo $message->getURL(); ?>"
                                                                                   data-calltoactionlabel="INVITE"
                                                                                   data-calltoactionurl="https://developers.google.com/+/web/share/interactive?invite=true"
                                                                                   data-cookiepolicy="single_host_origin"
                                                                                   data-prefilltext="<?php echo strip_tags(Signal::parseLinks(str_replace("<br>", "\n", substr($text, 0, $endpos)))) . '...'; ?>"><i class="icon-circle-list"></i>Google+</a>
                                                                            </li>
                                                                        <?php endif; ?>
                                                                        <?php if ($linkedin['accountid'] != 'undefined') : ?>
                                                                            <li data-id="903">
                                                                                <a class="retweet_this" data-action="linkedin" data-platform-id="377747108537061378"><i class="icon-circle-list"></i>LinkedIn</a>
                                                                            </li>
                                                                        <?php endif; ?>
                                                                    </ul>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </li>
                                                <?php endif; ?>
                                                <li class="mention-action-button mention-actions mention-tag">
                                                    <div class="btn-group">
                                                        <button data-toggle="dropdown" class="btn btn-danger"><i class="icon-action-tag"></i><div><font><font>Tag</font></font></div><i class="icon-action-dropdown"></i></button>
                                                    </div>
                                                </li>

                                                <li class="mention-action-button"><button class="btn btn-danger add-task" messageid="<?php echo $signal->messageID; ?>" streamid="<?php echo $signal->streamID; ?>"><i class="icon-action-addtask"></i>

                                                        <div>
                                                            <em>Add&nbsp;</em>task
                                                        </div></button></li>

                                                <li class="mention-action-button go-top-button"><button class="btn btn-danger"><i class="icon-go-top"></i></button></li>
                                                <div class="tags-holder-container">
                                                    <?php
                                                    $mtag = $signal->findTag();
                                                    if (is_array($mtag))
                                                        foreach ($mtag as $tag) {
                                                            echo '<div class="tag-holder-container"><label>' . $tag->tagName . '</label><a class="remove-tag">x</a></div>';
                                                        }
                                                    ?>
                                                </div>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="annotables-replies-content">
                                <div class="annotations-holder-container">
                                    <div class="mozaic-widget widget-annotable_tasks_and_posts" data-guid="widget-195" data-initialized="true" >


                                        <div class="tasks-and-posts">
                                            <div class="annotable-tasks-and-posts">
                                                <div class="mozaic-widget task-14349 first_overall last_overall first last widget-task" data-guid="widget-219" data-initialized="true" >


                                                    <div class="mention-container stream-task-container <?php echo $completeText ?>">
                                                        <div class="mention-right-content">
                                                            <div class="mention-right-wrapper">
                                                                <div class="mention-right-container">
                                                                    <div class="mention-content">
                                                                        <div class="user-author-mention-actions mention-top-bar">
                                                                            <div class="float-left">
                                                                                <img src="http://www.gravatar.com/avatar/<?php echo md5(strtolower($user1->email)); ?>?d=http://pulse.buzzmetrics.vn/Images/pulse_75.png">

                                                                                <p><strong><?php echo $user1->name ?></strong> <span>assigned a task to</span></p>
                                                                            </div>

                                                                            <div class="float-left">
                                                                                <img src="http://www.gravatar.com/avatar/<?php echo md5(strtolower($user2->email)); ?>?d=http://pulse.buzzmetrics.vn/Images/pulse_75.png">

                                                                                <p><strong><?php echo $user2->name ?></strong></p>
                                                                            </div><span class="task-posted-time" data-timestamp="<<?php echo $timestamp ?>" data-timestamp-format="MMM D YYYY h:mm A"><?php echo $dateCreated->format("M d Y h:m A") ?></span>
                                                                        </div>

                                                                        <div class="mention-core task-core">
                                                                            <div class="mention-core-wrapper">
                                                                                <div class="mention-author-image">
                                                                                    <div class="complete-task-button">
                                                                                        <div class="complete-task-img mark-complete">
                                                                                            <i class="icon-complete-task-big"></i>
                                                                                        </div>

                                                                                        <p><?php echo strtoupper($completeText); ?></p>
                                                                                    </div>
                                                                                </div>

                                                                                <div class="mention-content-full" style="margin-left: 0">
                                                                                    <p class="author-name"><?php echo $task->taskName; ?></p>

                                                                                    <p class="mention-text" text="<?php echo $task->taskNote; ?>"><?php
                                                                                        if ($completeText)
                                                                                            echo ucfirst($completeText) . " '" . $task->taskNote . "' with solution '" . $task->action . "'";
                                                                                        else
                                                                                            echo $task->taskNote;
                                                                                        ?></p>
                                                                                </div>
                                                                            </div>

                                                                            <ul class="mention-action-bar">
                                                                                <li class="mention-action-button"><button class="mark-complete btn btn-danger" taskId="<?php echo $task->taskId; ?>"><i class="icon-complete-task"></i> <?php echo $completeAction; ?></button></li>

                                                                                <li class="mention-action-button discard-button"><button class="delete-task btn btn-danger" data-id="14349" taskId="<?php echo $task->taskId; ?>"><i class="icon-action-delete"></i></button></li>
                                                                            </ul>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="clear"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="clear"></div>
                    </div>

                    <div class="clear"></div>
                </div>
            </div>
        </li>
    <?php
    endforeach; ?>